/**
 * @description Description
 *
 * @author Candy <candy.yan@motionglobal.com>
 * @date  Creation Date 2018/7/27
 */

import {mapState, mapMutations} from 'vuex';
import crypto from 'crypto';

export const siderMenu= {
  methods: {
    ...mapMutations([ 'RECORD_CURMENU' ]),
    curMenuSelected(curRouter) {
      let activeName, openNames;
      switch (true) {
        case curRouter.indexOf('/dashbord') >= 0:
          activeName = '1-1';
          openNames = '1';
          break;
        case curRouter.indexOf('/account-set') >= 0:
          activeName = '2-1';
          openNames = '2';
          break;
        case curRouter.indexOf('/supplier-PO/wait-to-confirm') >= 0:
          activeName = '3-1';
          openNames = '3';
          break;
        case curRouter.indexOf('/supplier-PO/confirmed') >= 0:
          activeName = '3-2';
          openNames = '3';
          break;
        case curRouter.indexOf('/supplier-PO/wait-to-ship-WH') >= 0:
          activeName = '3-3';
          openNames = '3';
          break;
        case curRouter.indexOf('/supplier-PO/shipped') >= 0:
          activeName = '3-4';
          openNames = '3';
          break;
        default:
          activeName = '1-1';
          openNames = '1';
          break;
      }
      return {
        activeName,
        openNames
      }
    },
    goToPath (name) {
      let curMenuSelected = {};
      switch (name) {
        case '1-1':
          this.$router.push('/dashbord');
          curMenuSelected = {
            activeName: '1-1',
            openNames: '1'
          };
          break;
        case '2-1':
          this.$router.push('/account-set');
          curMenuSelected = {
            activeName: '2-1',
            openNames: '2'
          };
          break;
        case '3-1':
          this.$router.push('/supplier-PO/wait-to-confirm');
          curMenuSelected = {
            activeName: '3-1',
            openNames: '3'
          };
          break;
        case '3-2':
          this.$router.push('/supplier-PO/confirmed');
          curMenuSelected = {
            activeName: '3-1',
            openNames: '3'
          };
          break;
        case '3-3':
          this.$router.push('/supplier-PO/wait-to-ship-WH');
          curMenuSelected = {
            activeName: '3-1',
            openNames: '3'
          };
          break;
        case '3-4':
          this.$router.push('/supplier-PO/shipped');
          curMenuSelected = {
            activeName: '3-1',
            openNames: '3'
          };
          break;
        default:
          this.$router.push('/dashbord');
          curMenuSelected = {
            activeName: '1-1',
            openNames: '1'
          };
          break;
      }
      this.RECORD_CURMENU(curMenuSelected);
    }
  }
};

export const modalInstance = {
  methods: {
    modalInstance (type, title, content) {
      switch (type) {
        case 'info':
          this.$Modal.info({
            title: title,
            content: content
          });
          break;
        case 'success':
          this.$Modal.success({
            title: title,
            content: content
          });
          break;
        case 'warning':
          this.$Modal.warning({
            title: title,
            content: content
          });
          break;
        case 'error':
          this.$Modal.error({
            title: title,
            content: content
          });
          break;
      }
    }
  }
};

export const getmd5 = {
  methods: {
    getmd5 (password) {
      var md5 = crypto.createHash("md5");
      md5.update(password);
      password = md5.digest('hex');
      return password;
    }
  }
}
